﻿using System;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using log4net;
using System.Reflection;

namespace AnyOffice.general.system.rtx
{
    public partial class rtx_usersync : ModulePage
    {

        private static ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);//readonly

        
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                try
                {
                    Type type = Assembly.LoadFrom(Server.MapPath("/bin/RTX.dll")).GetType("RTX.RtxConfiguration", true);
                    object obj2 = Activator.CreateInstance(type);
                    object obj3 = type.GetMethod("IsSdkOk").Invoke(obj2, null);
                    if ((obj3 != null) && !Convert.ToBoolean(obj3.ToString()))
                    {
                        this.pnlMain.Visible = false;
                        this.litMessage.Text = base.ShowPrompt("RTX Server SDK 没有正确安装或者出现了问题，需要重新安装。", "rtx_userSync.aspx");
                        return;
                    }
                }
                catch (Exception exception)
                {
                    if (log.IsErrorEnabled)
                    {
                        log.Error("RTX", exception);
                    }
                }
            }
            if (this.Page.IsPostBack)
            {
                this.pnlMain.Visible = false;
                try
                {
                    Type type2 = Assembly.LoadFrom(Server.MapPath("/bin/RTX.dll")).GetType("RTX.RtxSdk", true);
                    object obj4 = Activator.CreateInstance(type2);
                    type2.GetMethod("UserSync").Invoke(obj4, null);
                    this.litMessage.Text = base.ShowPrompt("组织机构同步成功！", "rtx_userSync.aspx");
                }
                catch (Exception exception2)
                {
                    if (log.IsErrorEnabled)
                    {
                        log.Error("RTX", exception2);
                    }
                    this.litMessage.Text = base.ShowPrompt("组织机构同步失败：详细信息请查看日志！", "rtx_userSync.aspx");
                }
            }
        } 

    }
}
